package com.billjc.activity.controller;

import java.time.LocalDateTime;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.billjc.activity.Result.CodeMsg;
import com.billjc.activity.Result.Result;
import com.billjc.activity.service.EcsProcessServiceImpl;

import lombok.extern.slf4j.Slf4j;

@RestController
@Slf4j
/**
 * 执行流程的控制器
 * @author bruce
 *
 */
public class ProcessController {
	@Autowired
	private EcsProcessServiceImpl ecsProcessService;
	/**
	 * 开始ECS流程
	 * @param ecsInfo
	 * @return
	 */
	@PostMapping(value = "/doEcsProcess", produces = "application/json; charset=utf-8")
	public Result<String> doEcsProcess(@RequestParam(value="ecsInfo",required=true) String ecsInfo) {
		String processInstanceId = ecsProcessService.invoker(ecsInfo);
		log.info("{},启动ecs流程实例: {}",LocalDateTime.now(),processInstanceId);
		if (StringUtils.isNotEmpty(processInstanceId)) {
			return Result.success(processInstanceId);
		}
		return Result.error(CodeMsg.PROCESS_ERROR);
	}
}
